#!/usr/bin/env python

##  flamingo - 2D Game Engine
##  Copyright (C) 2009 Bradley Zeis
##
##  This program is free software: you can redistribute it and/or modify
##  it under the terms of the GNU General Public License as published by
##  the Free Software Foundation, either version 3 of the License, or
##  (at your option) any later version.
##
##  This program is distributed in the hope that it will be useful,
##  but WITHOUT ANY WARRANTY; without even the implied warranty of
##  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
##  GNU General Public License for more details.
##
##  You should have received a copy of the GNU General Public License
##  along with this program.  If not, see <http://www.gnu.org/licenses/>.
##
##  Bradley Zeis
##  bradzeis@gmail.com

import unittest
import pickle
import flamingo
import flmath_test

class TestMesh(unittest.TestCase):
    def setUp(self):
        self.m = flamingo.mesh.Mesh([flamingo.mesh.VMeshNode((111, 222)),
                                     flamingo.mesh.VMeshNode((333, 444)),
                                     flamingo.mesh.VMeshNode((111, 444))],
                                    [flamingo.mesh.MeshNode((111, 222)),
                                     flamingo.mesh.MeshNode((333, 444)),
                                     flamingo.mesh.MeshNode((111, 444))])

    def testAccess(self):
        self.assertEqual(len(self.m), 3)
        v = self.m.v[0]
        t = self.m.t[0]
        self.assertEqual(flamingo.mesh.MeshNode, type(t))
        self.assertEqual(flamingo.mesh.VMeshNode, type(v))


class TestMeshNode(flmath_test.TestVector):
    def setUp(self):

        self.m = flamingo.mesh.Mesh([flamingo.mesh.VMeshNode((111, 222)),
                                     flamingo.mesh.VMeshNode((333, 444)),
                                     flamingo.mesh.VMeshNode((111, 444))],
                                    [flamingo.mesh.MeshNode((111, 222)),
                                     flamingo.mesh.MeshNode((333, 444)),
                                     flamingo.mesh.MeshNode((111, 444))])
        self.v = self.m.t[0]

        self.bad = [(8, {'foo': 'bar'}),
                    ("meow!", "imah vector!")]

class TestVMeshNode(flmath_test.TestVector):
    def setUp(self):

        self.m = flamingo.mesh.Mesh([flamingo.mesh.VMeshNode((111, 222)),
                                     flamingo.mesh.VMeshNode((333, 444)),
                                     flamingo.mesh.VMeshNode((111, 444))],
                                    [flamingo.mesh.MeshNode((111, 222)),
                                     flamingo.mesh.MeshNode((333, 444)),
                                     flamingo.mesh.MeshNode((111, 444))])
        self.v = self.m.v[0]

        self.bad = [(8, {'foo': 'bar'}),
                    ("meow!", "imah vector!")]

    def testAccess(self):
        v = self.v.copy()
        self.assertEqual(v.x, 111)
        self.assertEqual(v.y, 222)
        v.x = 333
        v[1] = 444
        self.assertEqual(v[0], 333)
        self.assertEqual(v[1], 444)

        ## More stuff later


##-------- Test Suite
testmesh    = unittest.TestLoader().loadTestsFromTestCase(TestMesh)
testnode    = unittest.TestLoader().loadTestsFromTestCase(TestMeshNode)
testvnode   = unittest.TestLoader().loadTestsFromTestCase(TestVMeshNode)

testsuite = unittest.TestSuite((testmesh, testnode, testvnode))

if __name__ == "__main__":
    unittest.TextTestRunner(verbosity=2).run(testsuite)
